<%@ page contentType="text/html;charset=UTF-8"%>
<!DOCTYPE html>
<html>
	<head>
		<title>用户列表</title>
		<%@ include file="/common/meta.jsp" %>
    <%@ include file="/common/import.jsp" %>
	<%@ include file="uct-import.jsp" %>
	<script>
	$(function() {
			$('#userList').datagrid( {
			toolbar:[					
			         {
			              text:'用户删除',
			              iconCls:'icon-cut',
			              handler:function(){deleteUser();}
			          }
			            ,'-',
			          {
			              text:'用户启用',
			              iconCls:'icon-edit',
			              handler:function(){saveUser('edit');}
			          }
			          
			        ],
					onDblClickRow:function(row){
						saveUser('edit');
					}
				});
				
			$('#userList').datagrid('getPanel').panel({
					onExpand: function(){
						$('#userActWin').panel('close');
					}
			});
		

			
		});
		
	$(function(){
			$('#userActWin').panel({
		  		onClose:function(){
		  			$('#userList').datagrid('getPanel').panel('expand');
		  		},
		  		onExpand:function(){
		  			$('#userList').datagrid('getPanel').panel('collapse');
		  		},
		  		onCollapse:function(){
		  			$('#userList').datagrid('getPanel').panel('expand');
		  		}
			});
	});
			
		function reload(){
			$('#userList').datagrid('reload');
		}
		
		
		
		//新的查询功能
		function searchUserNew(){	
			$('#userList').datagrid('options').pageNumber=parseInt("1"); 
	    	var queryParams = $('#userList').datagrid('options').queryParams;	       
	        queryParams.userId = $('#userId').val();
	        queryParams.userEname = $('#userEname').val();
	        queryParams.userCname = $('#userCname').val();
	        $('#userList').datagrid("reload");
		}
		
		function clearSearch(){					
		    $('#userEname').val('');
		    $('#userCname').val('');
		    $('#userId').val('');
		}  
       	
       function saveUser(paraFlag){
			var node = getSelected();	
			if(node){
		       $.messager.confirm('确认','您确定要启用:<font color="red">'+node.userCname+'</font> ?',function(r){
		          if(r){
						$.ajax({
								type: "post",
								url: "${ctx}/uct/user/user!userReUserd.action?id="+node.userId,
								success: function(data){
									var result = jQuery.parseJSON(data);
							    	if(result.flag=='T'){
							    		$.messager.alert('提交结果', result.msg, 'info');
										var rowIndex = $('#userList').datagrid('getRowIndex',node);								
										$('#userList').datagrid('deleteRow', rowIndex);					
							    	}else{
							    		$.messager.alert('提交结果', '操作失败:'+result.msg, 'error');
							    	}        
								}
							});
		          		}
		       });		             		
		    }	
		}
		
		
		
		function getSelected(){
			var selected = $('#userList').datagrid('getSelected');
			if (selected){
				return selected;
			}else{
				$.messager.alert('提示', '请选择要操作的数据', 'info');
			}
		}
		
		function deleteUser(){					
			var node = getSelected();	
			if(node){
		       $.messager.confirm('确认','您确定要删除:<font color="red">'+node.userCname+'</font> ?',function(r){
		          if(r){
						$.ajax({
								type: "post",
								url: "${ctx}/uct/user/del.action?id="+node.userId,
								success: function(data){
									var result = jQuery.parseJSON(data);
							    	if(result.flag=='T'){
							    		$.messager.alert('提交结果', result.msg, 'info');
										var rowIndex = $('#userList').datagrid('getRowIndex',node);								
										$('#userList').datagrid('deleteRow', rowIndex);					
							    	}else{
							    		$.messager.alert('提交结果', '操作失败:'+result.msg, 'error');
							    	}        
								}
							});
		          		}
		       });		             		
		    }	
		}
		
		function closeUserAdd(){
			$('#userAddWin').window('close');
		}
	</script>
	</head>

	<body>
	<table class="planel-body">
			<tr>
				<td>用户账号</td>
				<td>
					<input id="userEname" name="userEname" value=""/>
				</td>
				<td>用户姓名</td>
				<td>
					<input id="userCname" name="userCname" value=""/>
				</td>
				
				<td>
					<a class="easyui-linkbutton" iconCls="icon-search"
						onclick="searchUserNew();">查询</a>
					<a class="easyui-linkbutton" iconCls="" onclick="clearSearch();">清空</a>
				</td>
			</tr>
		</table>
	<table id="userList" class="easyui-datagrid" title="用户列表"  data-options="rownumbers:true,singleSelect:true,iconCls:'icon-ok',pageList:[10,15,30],pagination:true,url:'${ctx}/uct/user/user!data.action?userStatus=-1'">
		<thead >
			<tr>
				<th data-options="field:'userEname',width:140">用户账号</th>
				<th data-options="field:'userCname',width:100">用户姓名</th>
				<th data-options="field:'orgEname',width:100">所属机构</th>
				<th data-options="field:'deptName',width:150">所属部门</th>
				<th data-options="field:'userType',width:110,
					formatter:function(value){
							if( value=='1'){return '交易会员';}
							else if(value=='2'){ return '业务人员';}
							else{return '';}
						}">用户类型</th>
				<th data-options="field:'userSex',width:80,
						formatter:function(value){
							if( value=='F'){
								return '女';
							}else if(value=='M'){
								return '男';
							}else{ 
								return '';
							}
						}">性别</th>
				<th data-options="field:'mobile',width:120">手机</th>
				<th data-options="field:'userStatus',width:100,
						formatter:function(value){
							if( value=='1'){
								return '<font color=blue>启用</font>';
							}else{ 
								return '<font color=red>停用</font>';
							}
							
						}
						">状态</th>
			</tr>
		</thead>
	</table>

	
</body>
</html>